﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Login.ModelLayer;

namespace Login.DB
{
    class DBCreateUser
    {
        public void creatUser(User u)
        {
       string cmdString="INSERT INTO Users (fName, lName, address, zipCode, city, licensPlate, phoneNumber, email, userName, password, rank) VALUES (@fName, @lName, @address, @zipCode, @city, @licensPlate, @phoneNumber, @email, @userName, @password, @rank)";
       string connString = "Data Source=balder.ucn.dk;User Id=dmaa0213_4;Initial Catalog=dmaa0213_4;Password=MaaGodt; Integrated Security=false";
       using (SqlConnection conn = new SqlConnection(connString))
{
    using (SqlCommand comm = new SqlCommand())
    {
        comm.Connection = conn;
        comm.CommandText = cmdString;
        comm.Parameters.AddWithValue("@fName", u.fName);
        comm.Parameters.AddWithValue("@lName", u.lName );
        comm.Parameters.AddWithValue("@address", u.address);
        comm.Parameters.AddWithValue("@zipCode", u.zipCode);
        comm.Parameters.AddWithValue("@city", u.city);
        comm.Parameters.AddWithValue("@licensPlate", u.licensPlate);
        comm.Parameters.AddWithValue("@phoneNumber", u.phoneNumber);
        comm.Parameters.AddWithValue("@email", u.email);
        comm.Parameters.AddWithValue("@userName", u.userName);
        comm.Parameters.AddWithValue("@password", u.password);
        comm.Parameters.AddWithValue("@rank", u.rank);
       
        try
        {
            conn.Open();
            
            comm.ExecuteNonQuery();
        }
        catch(SqlException e)
        {
            // do something with the exception
            // don't hide it
        }
    }
       }
        }
    }
}
        
      

